from openpyxl import Workbook
import requests
from bs4 import BeautifulSoup
header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"
}
url = "https://movie.douban.com/"
re = requests.get ( url, headers=header )
soup= BeautifulSoup (re.text,'html.parser')
#print(re.text)
# #名称
title1=[]
title2=[]
title = soup.findAll(name="div",attrs={"class":"billboard-bd"})
# for i in title:
#      # print(i.string)
#      # print(i.text)
#       print ( i.stripped_strings )
#      nos.append ( li.contents[-2].string )
#      host.append ( li.contents[3].string )
#      name.append ( li.contents[5].string )
# print ( host )
# #pa1 = soup.findAll(name="div",attrs={"class":"billboard-bd"})
pa2 = soup.findAll(name="td",attrs={"class":"order"})
pa3=soup.findAll(name="td",attrs={"class":"title"})
# #for p1 in pa1:
for p2 in pa2:
    title1.append(p2.string)
    print(p2.string)
for p3 in pa3:
     title2.append(p3.string)
     print(p3.string)
wb = Workbook()
ws = wb.active
rows=[]
ws.append(["排名","名称"])
# ws['A1'] = "排名"
# ws['B1'] = "名称"
for r in range(len(title1)):
     ws.append([title1[r],title2[r]])
wb.save("一周排行榜.xlsx")